package com.fahai.web.service.impl;/**
 * Created by Lilinjun on 17/6/27.
 */

import com.fahai.common.PageVo;
import com.fahai.web.dao.AnYuanDao;
import com.fahai.web.entity.Anyuan;
import com.fahai.web.service.SourceService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 案源接口实现类
 *
 * @author
 * @create 2017-06-27 下午3:37
 **/
@Service
@Transactional(rollbackFor = DataAccessException.class)
public class SourceServiceImpl implements SourceService {
    @Autowired
    AnYuanDao dao;

    /**
     * 查询
     *
     * @param anyuan
     * @return
     */
    @Override
    public PageVo selectSourceList(Anyuan anyuan, PageVo pageVo) {
        Page<Anyuan> page = PageHelper.startPage(pageVo.getPageNum(), pageVo.getPageSize());
        String orderByStr = anyuan.getPxzd() + " " + anyuan.getPxfx();
        if (orderByStr.trim().equals("")) {
            orderByStr = "aycode desc";
        }
        PageHelper.orderBy(orderByStr);
        List<Anyuan> lists=dao.queryAnyuanLists(anyuan);
        pageVo.setResult(lists);
        return pageVo;
    }

    /**
     * 统计总行数
     *
     * @param anyuan
     * @return
     */
    @Override
    public int getCount(Anyuan anyuan) {
        return dao.queryCount(anyuan);
    }

    /**
     * 冻结解冻
     *
     * @param idlist
     * @param type
     */
    @Override
    public void freeze(List<Integer> idlist, String type) {
        if ("freeze".equals(type)) {
            dao.freeze(idlist);
        } else {
            dao.unFreeze(idlist);
        }
    }

    @Override
    public List<Anyuan> selectSourceListxls(Anyuan anyuan) {
        List<Anyuan> lists=dao.queryAnyuanLists(anyuan);
        return lists;
    }

    /**
     * 更新案源
     *
     * @param anyuan
     */
    @Override
    public void updateAnyuan(Anyuan anyuan) {
        dao.updateByPrimaryKeySelective(anyuan);
    }
}
